﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using TrainingWorkshop.Model;
using TrainingWorkshop.DALFactory;
using TrainingWorkshop.IDAL;
using TrainingWorkshop.DAL_EF;

namespace BLL
{
    /// <summary>
    /// Author: Sissi Zeng
    /// Date：2012-08-08 21:25
    /// get course List from Factoyr
    /// </summary>
    public class CourseSearch
    {


        /// <summary>
        /// Constructor
        /// no parameter
        /// </summary>
        public CourseSearch()
        {

        }

        /// <summary>
        /// Generate Report of CourseList
        /// </summary>
        /// <param name="condition">Given Condition</param>
        /// <returns>List of Course</returns>
        public List<TrainingWorkshop.Model.CourseList> GenerateReport(Condition condition)
        {
            List<TrainingWorkshop.Model.CourseList> a = new List<CourseList>();
            //handle input
            if (condition.CourseName.Length == 0)
            {
                condition.CourseName = "";
            }
            if (condition.TeacherName.StartsWith("--"))
            {
                condition.TeacherName = "";
            }
            if (condition.LevelName.StartsWith("--"))
            {
                condition.LevelName = "";
            }

            //call Factory
            IFactory factory = new ApplicationContext().CreateFactory("EF");
            ICourseListRepository couseListRep = factory.CreateCourseListRepository();

            //get CourseList
            List<TrainingWorkshop.Model.CourseList> courseList = couseListRep.SelectAllCourses(condition);

            //handle display detail
            if (courseList != null)
            {
                foreach (TrainingWorkshop.Model.CourseList c in courseList)
                {
                    if (c.CourseStatus)
                    {
                        c.StatusDisplay = "Open";
                    }
                    else
                    {
                        c.StatusDisplay = "Close";
                    }

                }
            }
            return courseList;

        }
    }
}
